package usaco.c2010.january.bronze;

import java.util.Scanner;

/*
 * p3561
 * USACO 2010 January - Bronze
 */


public class p3561 {

	static int M, F;
	static String[] MD, FD;
	static int[][] matrix;

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);
		M = scanner.nextInt();
		F = scanner.nextInt();
		MD = new String[M];
		FD = new String[F];
		for (int i=0;i<M;++i) {
			MD[i] = scanner.next();
		}
		for (int i=0;i<F;++i) {
			FD[i] = scanner.next();
		}
		matrix = new int[M][F];
		for (int i=0;i<M;++i) {
			for (int j=0;j<F;++j) {
				for (int k=0;k<M;++k) {
					if (k != i) {
						if (isChildOf(MD[k],MD[i],FD[j])) {
							matrix[i][j]++;
						}
					}
				}
				for (int k=0;k<F;++k) {
					if (k != j) {
						if (isChildOf(FD[k],MD[i],FD[j])) {
							matrix[i][j]++;
						}
					}
				}
				System.out.print(matrix[i][j]);
				if (j < F - 1) {
					System.out.print(" ");
				}
				else {
					System.out.println();
				}
			}
		}

	}

	private static boolean isChildOf(String ch, String fa, String mo) {
		int len = 25;
		for (int i=0;i<len;++i) {
			if (ch.charAt(i) == fa.charAt(i) || ch.charAt(i) == mo.charAt(i)) {
				continue;
			}
			else {
				return false;
			}
		}
		return true;
	}

}
